import React, { useEffect, useState } from 'react';
import axios from 'axios';

export const UseAPI = () => {
  const [data, setData] = useState([]);

  useEffect(() => {
    fetchData('u-cvv0dspd58bUt34pxY8G02113j1g4hjboO00h4eGa4tt');
  }, []);

  const fetchData = async (token) => {
    try {
      const response = await axios({
        method: 'GET',
        url: 'http://112.74.171.79:8080/aicms/:8080/aicms/project/queryPojectList',
        headers: {
          'user_access_token': token
        }
      });

      const responseData = response.data;
      setData(responseData);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <div className='useapi'>
      {/* 使用数据渲染组件 */}
      {data.map((item) => (
        <div key={item.id}>
          <h3>{item.title}</h3>
          <p>{item.description}</p>
        </div>
      ))}
    </div>
  );
};
